package com.taotao.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.manage.pojo.ItemDesc;
import com.taotao.manage.service.ItemDescService;

/**
 * @Description:商品详情
 * @author:     mingxu
 */
@RequestMapping("item/desc")
@Controller
public class ItemDescController {

	@Autowired
	private ItemDescService itemDescService;

	/**
	 *	根据商品id查询商品详情
	 *		请求路径： item/desc  GET请求
	 *		请求参数： 拼接在请求路径上的商品id
	 *		结果响应： ItemDesc
	 */
	@RequestMapping(value = "{itemId}") //使用springmvc的占位符接收请求路径上拼接的数据
	public ResponseEntity<ItemDesc> queryById(@PathVariable(value = "itemId") Long itemId) {

		try {
			if (itemId < 0) {
				return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
			}

			//查询商品详情
			ItemDesc itemDesc = itemDescService.queryById(itemId);
			if (itemDesc == null) {
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
			}
			return ResponseEntity.status(HttpStatus.OK).body(itemDesc);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
}
